package common.util;

/**
 * @(#) DefaultLoggerWriter.java
 * Copyright 1999-2000 by  LG-EDS Systems, Inc.,
 * Information Technology Group, Application Architecture Team,
 * Application Intrastructure Part.
 * 236-1, Hyosung-2dong, Kyeyang-gu, Inchun, 407-042, KOREA.
 * All rights reserved.
 *
 * NOTICE !      You can copy or redistribute this code freely,
 * but you should not remove the information about the copyright notice
 * and the author.
 *
 * @author  WonYoung Lee, wyounglee@lgeds.lg.co.kr.
 */

public class DefaultLoggerWriter extends LoggerWriter {
    
    /**
     * @param mode LoggerWriter.SYS, LoggerWriter.ERR, LoggerWriter.WARN,
     *                        LoggerWriter.INFO, LoggerWriter.DEBUG.
     */
    public DefaultLoggerWriter(int mode) {
        super(mode);
    }
    
    /**
     * getPrefixInfo The default message prefix.
     */
    protected String getPrefixInfo(Object o) {
        StringBuffer info = new StringBuffer();
        info.append('[');
        
        if ( o == null ) {
            info.append("null");
        } else if ( o instanceof javax.servlet.http.HttpServletRequest ) {
            javax.servlet.http.HttpServletRequest req =	(javax.servlet.http.HttpServletRequest)o;
            info.append(req.getRequestURI() +",");
            String user = req.getRemoteUser();
            if ( user != null ) info.append(user+",");
            info.append(req.getRemoteAddr());
        } else {
            Class c = o.getClass();
            String fullname = c.getName();
            String name = null;
            int index = fullname.lastIndexOf('.');
            if ( index == -1 ) name = fullname;
            else name = fullname.substring(index+1);
            info.append(name);
        }
        
        if ( o == null )
            info.append("] ");
        else
            info.append(":" + o.hashCode() + "] ");
        
        return info.toString();
    }
}